﻿layui.use(['layer','form'], function () {
    var $ = layui.jquery,form = layui.form(), layer = layui.layer;
    $('.on-shelves').click(function () {
        var id = $(this).parent().children('input[type="hidden"]').val();
        var index = layer.open({
            type: 1,
            id: 'frame_id',
            content: '是否上架此商品' + id,
            btn: ['是的', '点错了'],
            btnAlign: 'c',
            shade: 0.5,
            yes: function () {
                pullIdByAjax('/Goods/OnShelvesGoods', id);
                layer.close(index);
            },
            btn2: function () {
                layer.close(index);
            }
        })
    })

    $('.un-shelves').click(function () {
        var h = $(this).parent().parent().html();
        var id = $(this).parent().children('input[type="hidden"]').val();
        var index = layer.open({
            type: 1,
            id: 'frame_id',
            area:['800px','200px'],
            content: h,
            btn: ['是的', '点错了'],
            btnAlign: 'c',
            shade: 0.5,
            yes: function () {
                pullIdByAjax('/Goods/OffShelvesGoods', id);
                layer.close(index);
            },
            btn2: function () {
                layer.close(index);
            }
        })
    })

    $('.delete').click(function () {
        var table = '<table class="layui-table" lay-even lay-skin="row"><colgroup><col width="150"><col width="200"><col> </colgroup><thead><tr><th>商品名</th><th>库存</th><th>售价</th><th>备注</th><th>状态</th><th>操作</th></tr></thead><tbody>'
        var rtable = '</tbody></table>';
        var html = "";
        var h = $(this).parent().parent().html();
        var id = $(this).parent().children('input[type="hidden"]').val();
        $.ajax({
            url: "/Goods/GetGoodsDetail",
            data: { goodsId: id },
            dataType:'html',
            type: "post",
            async:true,
            success: function (data) {
                html = data.html;
            }
        })
        var index = layer.open({
            type: 1,
            id: 'frame_id',
            area: ['800px', '200px'],
            content: html,
            btn: ['是的', '点错了'],
            btnAlign: 'c',
            shade: 0.5,
            yes: function () {
                pullIdByAjax('/Goods/DeleteGoods', id);
                layer.close(index);
            },
            btn2: function () {
                layer.close(index);
            }
        })
    })

    var pullIdByAjax = function(nurl,id){
        $.ajax({
            url: nurl,
            type: 'POST',
            data: {
                goodsId: id,
            },
            success: function (data) {
                if (data.success != "") {
                    layer.msg(data.success);
                    console.log(data.success);
                }
                else {
                    layer.msg(data.error);
                }
            }
        })
    }
})